﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Libraries.Common;
using Libraries.Entities;

namespace Libraries.Repositories
{
    public class LanguageTypeRepository
    {
        private static LanguageType ParseToEntityLanguageType(IDataRecord dataReader)
        {
            if (dataReader != null)
            {
                return new LanguageType
                {
                    LanguageTypeId = dataReader["LanguageTypeId"].ToInt32OrDefault(),
                    LanguageName = dataReader["Language"].ToStringOrDefault(),
                    Note = dataReader["Note"].ToStringOrDefault()
                };
            }
            return null;
        }
        public Collection<LanguageType> ListAllLanguageType()
        {
            Collection<LanguageType> list = null;
            if(!string.IsNullOrEmpty(ProcedureConfiguration.FetchAllLanguageType))
            {
                using(var result = RepositorySql.SqlHelper.ExecuteReader(ProcedureConfiguration.FetchAllLanguageType,ConnectionConfiguration.ConnectionString))
                {
                    if(result!=null)
                    {
                        list = new Collection<LanguageType>();
                        while (result.Read())
                        {
                            list.Add(ParseToEntityLanguageType(result));
                        }
                    }
                }
            }
            return list;
        }
    }
}
